#include <iostream>
#include <vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128;
const int N = 1e6 + 5;

const int mod = 998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    vector<ll> A(n), B(n);
    vector<ll> dA(n + 1, 0), dB(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
        A[i] %= mod;
    }
    for (int i = 0; i < n; ++i) {
        cin >> B[i];
        B[i] %= mod;
    }
    
    // 预处理前缀和数组
    vector<ll> sum(n + 1, 0);
    vector<ll> prefixB(n + 1, 0);
    vector<ll> prefixA(n + 1, 0);
    vector<ll> prefixOne(n + 1, 0);
    
    for (int i = 0; i < n; ++i) {
        sum[i + 1] = (sum[i] + A[i] * B[i]) % mod;
        prefixB[i + 1] = (prefixB[i] + B[i]) % mod;
        prefixA[i + 1] = (prefixA[i] + A[i]) % mod;
        prefixOne[i + 1] = (prefixOne[i] + 1) % mod;
    }
    
    vector<ll> current_dA(n + 1, 0);
    vector<ll> current_dB(n + 1, 0);
    
    for (int i = 0; i < q; ++i) {
        int type;
        cin >> type;
        
        if (type == 1) {
            int l, r;
            ll x;
            cin >> l >> r >> x;
            dA[l - 1] = (dA[l - 1] + x) % mod;
            dA[r] = (dA[r] - x + mod) % mod;
        } else if (type == 2) {
            int l, r;
            ll x;
            cin >> l >> r >> x;
            dB[l - 1] = (dB[l - 1] + x) % mod;
            dB[r] = (dB[r] - x + mod) % mod;
        } else if (type == 3) {
            int l, r;
            cin >> l >> r;
            
            ll res = sum[r] - sum[l - 1];
            res = (res + mod) % mod;
            
            ll aa = 0, bb = 0;
            current_dA[0] = dA[0];
            current_dB[0] = dB[0];
            for (int j = 1; j < n; ++j) {
                current_dA[j] = (current_dA[j - 1] + dA[j]) % mod;
                current_dB[j] = (current_dB[j - 1] + dB[j]) % mod;
            }
            
            ll part1 = 0, part2 = 0, part3 = 0;
            
            ll sum_aa_B = 0;
            for (int j = l - 1; j < r; ++j) {
                sum_aa_B = (sum_aa_B + current_dA[j] * B[j]) % mod;
            }
            part1 = sum_aa_B % mod;
            
            ll sum_bb_A = 0;
            for (int j = l - 1; j < r; ++j) {
                sum_bb_A = (sum_bb_A + current_dB[j] * A[j]) % mod;
            }
            part2 = sum_bb_A % mod;
            
            ll sum_aa_bb = 0;
            for (int j = l - 1; j < r; ++j) {
                sum_aa_bb = (sum_aa_bb + current_dA[j] * current_dB[j]) % mod;
            }
            part3 = sum_aa_bb % mod;
            
            res = (res + part1 + part2 + part3) % mod;
            cout << res << endl;
        }
    }
    
    return 0;
}    